﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Text;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using PlugNT.Cms.Core;
using PlugNT.Cms.Model;
using PlugNT.Cms.BLL;
using PlugNT.Cms.Page;

namespace PlugNT.Cms.Web.Admin.Pre_Channel
{

    public partial class Admin : AdminPage
    {
        private ChannelInfo model = new ChannelInfo();
        private Channel curChannel = new Channel();
        private Article curArticle = new Article();
        public string pageTitle = "";

        protected string classType
        {
            get
            {
                return ViewState["clstype"].ToString();
            }
            set
            {
                ViewState["clstype"] = value;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            //权限检测
            this.CheckPower();

            pageTitle = "（网站分栏）";
            if (!IsPostBack)
            {
                BindData();
            }
        }

        #region 数据绑定
        private void BindData()
        {

            DataTable dt = curChannel.GetOrderList();

            this.rptMenuList.DataSource = dt.DefaultView;
            this.rptMenuList.DataBind();


        }
        #endregion


        #region 显示数据处理
        protected void rptMenuList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
            {
                Literal LitFirst = (Literal)e.Item.FindControl("LitFirst");
                Literal LitDir = (Literal)e.Item.FindControl("LitDir");
                Label LabClassNm = (Label)e.Item.FindControl("LabClassNm");

                string LitStyle = "<span style=\" width:{0}px; display:block; float:left; text-align:right; vertical-align:middle; line-height:25px; height:25px;\">{1}{2}</span>";
                string LitImg1 = "<img src=../images/openfolder.gif align=absmiddle />";
                string LitImg2 = "<img src=../images/folder.gif align=absmiddle />";
                string LitImg3 = "<img src=../images/t.gif align=absmiddle />";

                DataRowView drv = (DataRowView)e.Item.DataItem;
                int clsListLen = Convert.ToInt32(drv["clslistlen"]);
                string createpath=drv["createpath"].ToString();
                if (clsListLen == 1)
                {
                    LabClassNm.Font.Bold = true;
                    LitFirst.Text = LitImg1;
                }
                else
                {
                    LitFirst.Text = string.Format(LitStyle, clsListLen * 20, LitImg3, LitImg2);
                }
                LitDir.Text = "*/"+createpath;
            }
        }
        #endregion

        #region 编辑删除处理
        protected void rptMenuList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            HiddenField hidClassId = (HiddenField)e.Item.FindControl("hidClassId");
            HiddenField hidClassTag = (HiddenField)e.Item.FindControl("hidClassTag");
            Label LabClassNm = (Label)e.Item.FindControl("LabClassNm");
            switch (e.CommandName.ToLower())
            {
                //case "btnedit":
                //    this.txtClassName.Text = LabClassNm.Text.Trim();
                //    this.txtClassTagName.Text = hidClassTag.Value.Trim();
                //    this.txtClassTagName.BackColor = System.Drawing.Color.Gray;
                //    this.txtClassTagName.ReadOnly = true;
                //    this.HidClassId.Value = hidClassId.Value.Trim();
                //    this.DdlMenu.SelectedValue = Channel.GetParentClsno(hidClassId.Value.Trim()).Trim();
                //    this.btnAdd.Visible = false;
                //    this.btnEdit.Visible = true;
                //    //设置类别已经更新了
                //    //CmsSystem.IsChannelUpdated = true;
                //    break;
                case "btndelete":
                    string clslist = curChannel.GetClslistByClsno(hidClassId.Value, false);
                    bool flag = false;
                    string error = "";
                    if (clslist != "")
                    {
                        if (!curChannel.Delete(hidClassId.Value))
                        {
                            error = "类别删除记录个数为等于0";
                        }
                        if (!curArticle.Delete(clslist))
                        {
                            error += "文章删除记录个数为等于0";
                        }
                        if (error == "")
                        {
                            flag = true;
                        }
                    }

                    if (flag)
                    {
                        Page.ClientScript.RegisterStartupScript(Page.GetType(), "ajaxjs", "alert('所选栏目删除成功！')", true);
                    }
                    else
                    {
                        Page.ClientScript.RegisterStartupScript(Page.GetType(), "ajaxjs", string.Format("alert('删除操作失败，请与管理员联系！{0}')",error), true);
                    }
                    //设置类别已经更新了
                    //CmsSystem.IsChannelUpdated = true;
                    BindData();
                    break;
            }
        }
        #endregion



    }
}
